<!-- 我的表格 -->

<template>
  <WebTable>
    <RowIndex />

    <RowPhoto label="封面" bind="cover" />

    <RowTitle label="问卷标题" bind="title" :minWidth="200" />

    <RowDict label="发送类型" bind="questionnaireType" :dict="DICT.SEND_TYPE" />

    <RowNum label="发送人数" bind="sendUserNum" />

    <RowNum label="答卷数量" bind="answerNum" />

    <!-- <RowSwitch label="是否匿名" bind="anonymous" :width="120" />

    <RowSwitch label="允许修改" bind="edit" :width="120" />

    <RowDate label="截止日期" bind="endDate" /> -->

    <RowStatus width="auto" />

    <RowStatus label="启动状态" bind="startStatus" :dict="DICT.START_STATUS" width="auto" />

    <RowTime label="创建时间" bind="createTime" />

    <RowOperate :width="290">
      <template #default="{ row }">
        <BtnText :title="MAP.SHOW || CORE.MAP.TIP_SHOW" @click="openNewOneShow(row)" />

        <BtnText v-if="checkPass(row)" v-bind="getRejProp(row)" @click="toRej(row)" />
        <BtnText v-else v-bind="getPassProp(row)" @click="toPass(row)" />

        <BtnText :title="MAP.EDIT || CORE.MAP.TIP_EDIT" @click="toEdit(row)" />

        <BtnText title="复制" @click="toCopy(row)" />

        <BtnText title="统计" @click="windowDetail(row)" />

        <BtnText :title="MAP.DEL || CORE.MAP.TIP_DEL" red @click="openDel(row)" />
      </template>
    </RowOperate>
  </WebTable>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import mixDetailToTable from '@admin/components/detail/mixDetailToTable'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'MyTable',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [mixDetailToTable('', 'DetailQuestionnaire')],

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    /**
     * 检查是否为通过
     */
    checkPass(row) {
      if (row.questionnaireType === 1) return row.status === 1
      else return row.startStatus === 1
    },

    /**
     * 获取通过属性
     */
    getPassProp(row) {
      const title = row.questionnaireType === 1 ? '发布' : '启动'
      return { title }
    },

    /**
     * 获取拒绝属性
     */
    getRejProp(row) {
      const title = row.questionnaireType === 1 ? '停止' : '暂停'
      return { title, red: true }
    },

    /**
     * 点击通过
     */
    async toPass(row) {
      const { MAP } = this
      MAP.PASS = this.getPassProp(row).title
      MAP.tipPass = `${MAP.PASS}${MAP.WORD}`
      MAP.tipPassContent = `${MAP.PREFIX}${MAP.PASS}${MAP.MIDDLE}${MAP.WORD}${MAP.SUFFIX}`
      this.openPass(row)
    },

    /**
     * 点击拒绝
     */
    async toRej(row) {
      const { MAP } = this
      MAP.REJ = this.getRejProp(row).title
      MAP.tipRej = `${MAP.REJ}${MAP.WORD}`
      MAP.tipRejContent = `${MAP.PREFIX}${MAP.REJ}${MAP.MIDDLE}${MAP.WORD}${MAP.SUFFIX}`
      this.openRej(row)
    },

    /**
     * 点击修改
     */
    async toEdit(row) {
      if (row.answerNum) {
        await CORE.CONFIRM.warning(`修改问卷将清除已填写的 ${row.answerNum} 份答卷，确定开始修改？`, '修改问卷')
      }
      this.openNewOneEdit(row)
    },

    /**
     * 点击复制
     */
    toCopy(row) {
      this.openNewOneAdd(row)
    },
  },
}
</script>
